export default {
  namespaced: true ,
  state: {
    count: 0,
  },
  getter: {
    oddOrEven(state){
      return state.count % 2 === 1 ? "奇数" : "偶数";
    }
  },
  actives: {
    increment({ commit }, val){
      commit("INCREMENT",val);
    },
    decrement({ commit }, val){
      commit("DECREMENT",val);
    },
    ifOddIncrement({ commit,state }, val){
      if (state.count % 2 === 1) {
        commit("INCREMENT", val);
      }
    },
    incrementAsync({ commit }, val){
      setTimeout(()=>{
        commit("INCREMENT", val);
      },1000)
    },
  },
  mutations: {
    INCREMENT(state,val){
      state.count += val ;
    },
    DECREMENT(state, val) {
      state.count -= val;
    },
  }
}